<?php
include("utils.php");
//=====================================================language=============================================
if($_SESSION['langname']=="")
{
	$language_url="languages/"."english".'/retrivepassword_add_language.php';
}
else
{
	$language_url="languages/".$_SESSION['langname'].'/retrivepassword_add_language.php';
}

include_once("$language_url");
//======================================================End============================================
	if($_POST['mode']=="Retrivepassword")
	{
	Retrive();
	}
	else
	{
	main_content("main();");
	}


function Retrive()
{
	if($_POST['mode']=="Retrivepassword")
	{
	$SUBMIT=$_POST['RETRive'];
	$getREQUESTVALUe=$_REQUEST['RP'];

		if(isset($SUBMIT) && $SUBMIT!= '')
		{
			$POSTVAlueOFREsetPASSword=trim($_POST['resETPASSword']);
			$UPDATEpassWORd="UPDATE ".SITEUSER." SET `password`='".md5(($POSTVAlueOFREsetPASSword))."' WHERE `forgotPassword`='".$getREQUESTVALUe."'";

			$EXECUTIONofUPDATEpassWORd=mysql_query($UPDATEpassWORd);
			
			if($EXECUTIONofUPDATEpassWORd)
			{
			$logmsg=SESSIONMESSAGE;
			$_SESSION['msgg']=$logmsg;
			header("location:".$GLOBALS['site_url']."login.php?logmsg=log");

			}

		}
		
		if($getREQUESTVALUe != '')
		{
			$SELECTUSERinformatioN="SELECT `password`,`userName` FROM ".SITEUSER." WHERE `forgotPassword`='".$getREQUESTVALUe."'";
echo $SELECTUSERinformatioN;
			$EXECUTIONofSELECTUSERinformatioN=mysql_query($SELECTUSERinformatioN);
			if(mysql_num_rows($EXECUTIONofSELECTUSERinformatioN) > 0 )
			{
				
				$HIDDENforgotPASS=$getREQUESTVALUe;
			}
			else
			{
				$GLOBALS['msg']="User Does Not Exist.";
			}
		}
	}
main_content("main();");
}	
?>
<script language="JavaScript" >
// Removes leading whitespaces
function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

// Removes leading and ending whitespaces
function trim( value ) {
	
	return LTrim(RTrim(value));
	
}


function Trim(str)
{  while(str.charAt(0) == (" ") )
  {  str = str.substring(1);
  }
  while(str.charAt(str.length-1) == " " )
  {  str = str.substring(0,str.length-1);
  }
  return str;
}

/************************************************TRIM IN JAVASCRIPT ENDS HERE*******************************************/

/*************************************** PASSWORD CHECK STARTS FROM HERE **********************************************/

function CHECK_password()
{

	if(document.getElementById("resETPASSword") != null)
	{
		if(document.getElementById("resETPASSword").value != '')
		{

			if(document.getElementById("resETPASSword").value.length < 6)
			{
				document.getElementById("resETPASSwordError").innerHTML="<br>Please Type Your Password Grater Then 6 charecters.";
				document.getElementById("resETPASSwordError").style.display='';
				document.getElementById("resETPASSword").ClassName="RedClass";
				document.getElementById("resETPASSword").focus();
				return false;
			}
			var str =Trim(document.getElementById("resETPASSword").value);
			if( str=='')
			{
				document.getElementById("resETPASSwordError").innerHTML="<br>Please Dont Give Space In Password Field.";
				document.getElementById("resETPASSwordError").style.display='';
				document.getElementById("resETPASSword").ClassName="RedClass";
				document.getElementById("resETPASSword").value="";
				return false;
			}
			else
			{
				document.getElementById("resETPASSwordError").innerHTML="";
				document.getElementById("resETPASSwordError").style.display='none';
				document.getElementById("resETPASSword").ClassName="NormalClass";		
			}		
		}
		else 
		{
//alert(document.getElementById("resETPASSword").value);

			document.getElementById("resETPASSwordError").innerHTML="<br>Please Type Your Password.";
			document.getElementById("resETPASSwordError").style.display='';
			document.getElementById("resETPASSword").ClassName="RedClass";
			document.getElementById("resETPASSword").focus();
			return false;
		}
	}
	if(document.getElementById("RETYPEresETPASSword") != null)
	{

		if(document.getElementById("RETYPEresETPASSword").value != '')
		{
//alert(document.getElementById("RETYPEresETPASSword").value);
//alert(document.getElementById("resETPASSword").value);



			if( document.getElementById("RETYPEresETPASSword").value != document.getElementById("resETPASSword").value )
			{
				document.getElementById("RETYPEresETPASSwordError").innerHTML="<br>Password Mismatch.";
				document.getElementById("RETYPEresETPASSwordError").style.display='';
				document.getElementById("RETYPEresETPASSword").ClassName="RedClass";
				document.getElementById("RETYPEresETPASSword").value="";
				document.getElementById("RETYPEresETPASSword").focus();
				return false;
			}
		}
		else
		{
			document.getElementById("RETYPEresETPASSwordError").innerHTML="<br>Please Retype Your Password.";
			document.getElementById("RETYPEresETPASSwordError").style.display='';
			document.getElementById("RETYPEresETPASSword").ClassName="RedClass";
			document.getElementById("RETYPEresETPASSword").focus();
			return false;
		}
	}
return true;
}

/*************************************** PASSWORD CHECK ENDS HERE **********************************************/
</script>
<?php 
function main()
{
?>

<form id="RESTEPassword" name="RESTEPassword" method="post" action="" onSubmit="return CHECK_password();">

<input type="hidden" name="mode" value="Retrivepassword" /><br />
<br />
<table width="827" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                          <td width="11"><img src="images/PinkBorderTopLeft.jpg" alt="" width="11" height="11"></td>
                          <td class="PinkBoxTopBg"><img src="images/spacer.gif" alt="" width="10" height="11"></td>
                          <td width="11"><img src="images/PinkBorderTopRight.jpg" alt="" width="11" height="11"></td>
                        </tr>
                      </table></td>
                  </tr>
                  <tr>
                    <td class="PinkTwosideBorder BoxContent" valign="top" align="center"><table width="100%" border="0" cellspacing="0" cellpadding="5">
		<tr>
			<td align="center">
				<table width="90%" border="0" align="center" cellpadding="5" cellspacing="0">
					<tr>
						<td  align="left" valign="middle">&nbsp;</td>
					</tr>
					<tr>
						<td  align="left" valign="middle">&nbsp;</td>
					</tr>
					<?php 
					if($GLOBALS['msg'] != '')
					{
					?>
					<tr>
						<td  align="center" valign="middle" style="color:#FF0000; font-weight:bold;"><?php echo $GLOBALS['msg']; ?></td>
					</tr>
					<?php
					}
					?>
					<tr>
						<td  align="left" valign="middle" style="font-size:12px;font-family:Arial, Helvetica, sans-serif;color:#42625C;"><?php echo SELECT ;?></td>
					</tr>
					<tr>
						<td align="left" valign="middle">&nbsp;</td>
					</tr>
					<tr>
						<td >
								<table width="80%" border="0" cellspacing="0" cellpadding="5">
									<tr>
										<td style="font-size:12px;font-family:Arial, Helvetica, sans-serif;"><?php echo NEWPASSWORD ;?> </td>
										<td  align="left">
										<input name="resETPASSword" type="password" id="resETPASSword" value="" />
										<span id="resETPASSwordError" style="display:none; color:#FF0000; font-weight:bold; font-size:11px;"></span>
										</td>
									</tr>
									<tr>
										<td colspan="2">&nbsp;</td>
									</tr>
									<tr>
										<td style="font-size:12px;font-family:Arial, Helvetica, sans-serif;"><?php echo REENTER; ?> </td>
										<td align="left">
										<input name="RETYPEresETPASSword" type="password" id="RETYPEresETPASSword" value="" />
										<span id="RETYPEresETPASSwordError" style="display:none; color:#FF0000; font-weight:bold; font-size:11px;"></span>
										</td>
									</tr>
									<tr>
										<td>&nbsp;</td>
										<td align="left"><input type="submit" name="RETRive" value="<?php echo RESET;?>" />
											<input type="hidden" name="FROGOTpassHIdden" id="FROGOTpassHIdden" value="<?php echo $HIDDENforgotPASS; ?>">
										</td>
									</tr>
								</table>
							</td>
					</tr>
					<tr>
						<td>&nbsp;</td>
						<td>&nbsp;</td>
					</tr>
				</table>
			</td>
		</tr>
	</table></td>
                  </tr>
                  <tr>
                    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                          <td width="11"><img src="images/PinkBorderBottomLeft.jpg" alt="" width="11" height="11"></td>
                          <td class="PinkBoxBottomBg"><img src="images/spacer.gif" alt="" width="10" height="11"></td>
                          <td width="11"><img src="images/PinkBorderBottomRight.jpg" alt="" width="11" height="11"></td>
                        </tr>
                      </table></td>
                  </tr>
                </table>

</form>
<?php } ?>